/**
 * 
 */
package org.david.code.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.david.code.dao.IGenericDao;
import org.david.code.service.IGenericService;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;
/**
 * 泛型Service，满足通用的增删改查(CRUD)的操作
 * 
 * 
 * 
 */
@Service("genericServiceImpl")
public class GenericServiceImpl<T> implements IGenericService<T> {
	/**
	 * GenericDao instance, set by constructor of child classes
	 */
	@Resource(name="genericDaoImpl")
	protected IGenericDao<T> dao;

	public GenericServiceImpl() {
	}

	public GenericServiceImpl(IGenericDao<T> genericDao) {
		this.dao = genericDao;
	}

	/**
	 * {@inheritDoc}
	 */
	public T get(Serializable id) {
		return dao.get(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public T getUniqueResult(final DetachedCriteria query) {
		return dao.getUniqueResult(query);
	}

	/**
	 * {@inheritDoc}
	 */
	public int getCount(DetachedCriteria query) {
		return dao.getCount(query);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<T> getList(DetachedCriteria query) {
		return dao.getList(query);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<T> getList(DetachedCriteria query, int firstResult,
			int maxResults) {
		return dao.getList(query, firstResult, maxResults);
	}

	/**
	 * {@inheritDoc}
	 */
	public void remove(T object) {
		dao.remove(object);
	}

	/**
	 * {@inheritDoc}
	 */
	public void remove(Serializable id) {
		dao.remove(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public T save(T object) {
		return dao.save(object);
	}

	
}
